const path = require('path');
const fs = require('fs');

const fullPath = path.join(__dirname,'info2.json')
const res = fs.readFileSync(fullPath,'utf-8');
// console.log(res);
// console.log(typeof(res));//string
const str = res.slice(5,-5);
// console.log(str.split(',\r\n  '));
const arr = str.split(',\r\n  ');
// console.log(arr);
//随机数获取
function getRandom(){
    let randNum = Math.floor(Math.random()*arr.length);
    return randNum;
}
const num = getRandom();
// console.log(arr[num]);
// console.log(typeof(arr[num]));
// JSON.parse(arr[num]).count+=1;
// console.log(JSON.parse(arr[num]));
const obj = JSON.parse(arr[num]);
obj.count+=1;
arr[num]=JSON.stringify(obj);
// console.log(obj);
console.log(`本次是第${obj.count}次抽中${obj.name}:`+arr[num]);
// console.log(arr);
// const str2 = JSON.stringify(arr);
// const str3 = arr.join(',\r\n  ')
// console.log('str2:', str2)
// console.log('str3:', '[\r\n  '+str3+'\r\n  ]')
const newJSON = '[\r\n  '+arr.join(',\r\n  ')+'\r\n  ]';
fs.writeFileSync('info2.json',newJSON);


